import { NotFound } from 'lin-mizar';
import { Sentence } from '../model/sentence';

class SentenceDao {
  
  static async getSentenceList(){
    return await Sentence.findAll();
  }

  static async addSentence(v){
    return await Sentence.create(v);
  }

  static async editSentence(id, v){
    const sentence = await Sentence.findByPk(id);
    if(!sentence){
      throw new NotFound();
    }

    return await sentence.update({...v});
  }
  
  static async deleteSentence(id){
    const sentence = await Sentence.findByPk(id);
    if(!sentence){
      throw new NotFound();
    }
    return await Sentence.destroy({
      where: {
        id
      }
    })
  }
}

export { SentenceDao };
